package com.gylang.common.jwt;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 安全用户模型
 * @author Louis
 * @date Jan 14, 2019
 */
@Data
@AllArgsConstructor
public class JwtUserDetails implements UserDetails {

	private static final long serialVersionUID = 1L;

    private Long id;
	private String username;
    private String password;
    private String salt;

    private List<String> permission;




    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {

        return permission.stream().map(GrantedAuthorityImpl::new).collect(Collectors.toList());
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }
}
